<?php

namespace Database\Seeders;

use App\Models\ConfigModel;
use Illuminate\Database\Seeder;

class ConfigSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // 初始化数据
        $params  = [
            'icon' => '/resources/static/icon.png',
            'name' => '程序员宝盒',
            'logo' => '/resources/static/logo.png',
            'title' => '程序员宝盒 - 程序员必备导航站',
            'keywords' => '程序员宝盒, 程序员导航, 程序员工具, 开发者资源, 编程学习, 在线工具, 技术社区, 代码分享, 开源项目, 程序员网站',
            'description' => '程序员宝盒，专为开发者打造的一站式导航与资源平台。这里收录了常用开发工具、编程学习网站、技术社区、开源项目、效率提升工具等优质内容，帮助程序员快速找到所需资源，提升开发效率。',
            'qq_image' => '/resources/static/qq_image.png',
            'wx_image' => '/resources/static/wx_image.png'
        ];

        // 循环处理数据
        $keyList = ['icon', 'name', 'logo', 'title', 'keywords', 'description', 'qq_image', 'wx_image'];
        $configList = ConfigModel::query()->whereIn('key', $keyList)->pluck('content', 'key');
        foreach ($keyList as $keyItem) {
            if (!isset($configList[$keyItem])) {
                ConfigModel::query()->create([
                    'key' => $keyItem,
                    'content' => $params[$keyItem] ?? ''
                ]);
            } else {
                ConfigModel::query()->where('key', $keyItem)->update(['content' => $params[$keyItem] ?? '']);
            }
        }
    }
}
